%% Description: settingsNe.m
% This settings file contains all the options to run the codes 
% created by *modeFinderRun.m* 

% =================================================================
%% I. priorStru: controls prior and how to generate starting values  

%% I.A Prior
% .fileName: name of xls file with the prior for parameters 
% 
% .priorSheet: name of the xls worksheet 
%
%.ssSheet: name of the xls worksheet with the prior for steady state. 
%           leave empty if none 
priorStru.fileName='BFMPrior'; % 'ModelPriors_Constant'; 
priorStru.priorSheet='prior'; 

priorStru.ssSheet=[];

%% I.B Starting Values 

%% Option 1 
% .randomGridStart==1 if wish to start from a uniform grid 
% .randomGridSheet  if previous flag =1, name of worksheet 
%   from where to load
priorStru.randomGridStart=0; 
priorStru.randomGridSheet='gridTight'; 

%% Option 2 
% if randomGridStart==0 it will check in randomPriorStart==1 
% if so, will generate starting values at random from prior 
priorStru.randomPriorStart=1; 

%% Option 3 
% if randomGridStart==0 && randomPriorStart==0 
% will load starting values from .startSheet 
% can have as many columns as desired 
priorStru.startSheet='startValue'; 

%% Additional Options 
% .numStrvals if .randomGridStart ==1 || .randomPriorStart==1 
%    number of starting values to generate 
%
% .seedNum to generate random numbers 
priorStru.seedNum=1000; 
priorStru.numStartVals=80; 


%% II. addsol
% Structure with additional inputs for the solution of the model 
% e.g. NLeadsFFRObs or NPrices 
% leave empty if non 
% Wage and Price Series Stuff

addsol.GDPCWCons=0; 
% addsol.measureEQ.wage.numSeries     = 1;
% addsol.measureEQ.wage.nameSeries    = {'Real Compensation'};
% addsol.measureEQ.price.numSeries     = 3;
% addsol.measureEQ.price.nameSeries    = {'GDPDEFL' 'PCE' 'CPI'};
% % addsol.measureEQ.invest.numSeries     = 1;
% % addsol.measureEQ.invest.nameSeries    = {'InvestObs'};
% addsol.measureEQ.tfp.numSeries     = 2;
% addsol.measureEQ.tfp.nameSeries    = {'Unadjusted TFP','Adjusted TFP'};
%addsol.measureEQ.e5y.numSeries     = 1;
%addsol.measureEQ.e5y.nameSeries    = {'E5YObs'};
% addsol.measureEQ.price.numSeries    = 3;		
% addsol.measureEQ.price.nameSeries   = {'JCXFEBM_LD100'	'JCMXFEM_LD100' 'PCUSLFEN_LD100SA'};
%% III. dataStru: settings for data, including subsamples  
% .fileName: names of XLS file 
%
% .loadPath: name of path where XLS file located 
%
% .start: sample start (need not coincide with first obs in XLS)
%
%  YYYY.00 = YYYY.Q1
%  YYYY.25 = YYYY.Q2
%  YYYY.50 = YYYY.Q3
%  YYYY.75 = YYYY.Q4
%
% .startest: initial observation to compute likelihood 
%            if > .start, means using observations 
%            to initialize filter 
%
% .finish:  last date of the data  
%
% .finishest: last obs to use in computing the likelihood 
%             this will almost alwas == .finish 
%
% .demean: ==1 if the data should be demeaned 
%             usually not in our models, as means inform parameters 
%
% .demeanType: if .demean==1, 
%               if .demeanType==1 demean using the whole loaded sample 
%               or .demeanType==2 only the sample used for the likelihood 
%
% .subSamples 
% if there are NB subsamples, need an [NB 2] cell 
% first column, string with starting date 
% second columns, string with ending data 
% e.g 
% dataStru.subSamples={'1990Q1','2007Q3';...
%                      '2007Q4','2013Q2'}; 
% leave empty if none 



dataStru.fileName='usdata_S1';
   
dataStru.loadPath=cr_dirpath(cucd,'BFM_mod','data'); 

dataStru.start    =1960; 

dataStru.startest =1960; 

dataStru.finish   =2007.75; 

dataStru.finishest=dataStru.finish;  

dataStru.demean     =0; 

dataStru.demeanType=2; 


%% Subsample 
dataStru.subSamples=[]; 
% dataStru.subSamples=cell(2,2); 
% dataStru.subSamples(1,:)={'1993Q1','2007Q3'}; 
% dataStru.subSamples(2,:)={'2007Q4','2013Q4'}; 



% ========================================================================
%% IV. *estimOpt* Optimization options 
% *estimopt*
%
% Additional options for Matlab's fmincon 
% Algorithm 
% FinDiffType   default is 'forward' can change to 'central' for higher 
%               resolution at higher cost 
%
% .funcName 
% 'csminwel'    Sims' minimization routine 
% 'fmincon'     Matlab's fmincon 

estimopt=optimset('MaxFunEvals',200000,'Display','iter',...
    'MaxIter',1000,'TolFun',1e-2);

estimopt.UseParalell='on'; 
estimopt.funcName='csminwel';

% =========================================================================
%% V. Additional options 
%
% .initialCond if ==1, then you will be providing the initial state and covariance
% through filterStru.aZero and filterStru.pZero, filteStru.aZeroDecomp
% 
% .diary ==1, write output of optimization into a .txt file 
%             only if not run in parallel
%
% .noHeesian==1, skip the Hessian, stds will be NAN 
%
% .mixedFreq==1, model is in mixed frequency 

flags.initialCond=0; 

flags.diary=0;

flags.noHessian=1; 

flags.mixedFreq=0;

if flags.initialCond
    load KFLast_s4 KFLast
    filterStru.aZero=KFLast.aZero;
    filterStru.pZero=KFLast.pZero;
    filterStru.aZeroDecomp=KFLast.aZeroDecomp;
clear KFLast;
end


%% V.b Storage 
%
% location.savePath, where output is stored 
% is automatically a subfolder of 
% location.loadPath, where the prior and settings file are loaded 
%
% e.g  location.loadPath=BMJ\Dtr\Prior One
%
% if in addition provide location.add2SavePath name will be 
% [location.add2SavePath,date]; 
% e.g location.savePath=BMJ\Dtr\Prior One\end 2008.5 01 18 14 
location.add2SavePath=[sprintf('end %4.2f',dataStru.finish),...
    ' ',estimopt.funcName,' ',priorStru.fileName];  

%% V.c Change Handle 
%
% can estimate model with say, modBMJDtr.m and then do the analysis with a
% larger mode called modBMJDtrObs.m code will automatically check solutions
% for observables are identical. 
model.add2Handle=[];

% ========================================================================
%% VI. Report: Choose what to report in the graphs and the generated report
%
% *.stateIRF*:      states for which to report IRFS 
%                   if write 'name lev' will be cumsum, e.g. 
%                   if yobs is the log-difference in output 
%                   requesting 'yobs lev' will deliver the IRF to the sum
%                   of the growth rates 
%
% *.stateSpectrum:*  states for which to report the spectrum 
%                    if write 'name lev' it will apply an inverse difference
%                    filter to obtain the spectrum for the level 
%% 
% *.stateMom*        statesfor which to report moments, including 
%                    variance decompositions at different horizons 
%
% *.subSamples*      This is difference from the estimation sample in
%                    dataStru. Even if the model has non-subsamples in estimation, 
%                    can request an unconditional historical decomposition on 
%                    a specific part of the sample 
%
% *.stateDecomp:*    states not observabe only for which to report
%                    historical decompositions and plots. The observables
%                    are automatically added to the list 

report.stateIRF={'consumption savers'
        'consumption: Non-Savers'
        'nominal interest rate'
        'investment'
        'labor'
        'output'
        'govt consumption'
        'aggregate consumption'
        'real wage'
        'govt debt'
        'inflation'
        'b/y ratio'
        'inflation CF'
        'b/y ratio CF'
        'tauk'
        'taul'
        'tauc'
        'real interest rate'
        'transfers total' 
        'transfers part'
        'price of bonds'
        'g shock'
        'funded tranfer shock'
        'unfunded tranfer shock'}; 

report.stateSpectrum=report.stateIRF;

report.stateDecomp={'consumption savers'
        'consumption: Non-Savers'
        'nominal interest rate'
        'investment'
        'labor'
        'output'
        'govt consumption'
        'aggregate consumption'
        'real wage'
        'govt debt'
        'inflation'
        'b/y ratio'
        'inflation CF'
        'b/y ratio CF'
        'tauk'
        'taul'
        'tauc'
        'real interest rate'
        'transfers total' 
        'transfers part'
        'price of bonds'
        'g shock'
        'funded tranfer shock'
        'unfunded tranfer shock'
        }; 
report.stateMom=report.stateDecomp; 
report.subSamples=[];
% report.subSamples={'2007q4','2013Q4'}; 

%% VII. solveopt: OPTIONS for  FZERO or FSOLVE solution of the model 
%  Only needed when solving the steady state requires a non-linear solver 
solveopt=optimset('MaxFunEvals',20000,'Display','off',...
    'MaxIter',5000,'TolFun',1e-10);


eviewsReport.states={'consumption savers'
        'consumption: Non-Savers'
        'nominal interest rate'
        'investment'
        'labor'
        'output'
        'govt consumption'
        'aggregate consumption'
        'real wage'
        'govt debt'
        'inflation'
        'b/y ratio'
        'inflation CF'
        'b/y ratio CF'
        'tauk'
        'taul'
        'tauc'
        'real interest rate'
        'transfers total' 
        'transfers part'
        'price of bonds'
        'g shock'
        'funded tranfer shock'
        'unfunded tranfer shock'}; 
    
eviewsReport.names={'consumption savers'
        'consumption: Non-Savers'
        'nominal interest rate'
        'investment'
        'labor'
        'output'
        'govt consumption'
        'aggregate consumption'
        'real wage'
        'govt debt'
        'inflation'
        'b/y ratio'
        'inflation CF'
        'b/y ratio CF'
        'tauk'
        'taul'
        'tauc'
        'real interest rate'
        'transfers total' 
        'transfers part'
        'price of bonds'
        'g shock'
        'funded tranfer shock'
        'unfunded tranfer shock'
        }; 

% forecast.states={'yobs (dy)','cobs (dc)','iobs (di)','Hours'}; 
% forecast.names ={'GDP growth','C growth','I growth','Hours'}; 
% forecast.N     = 16; 

